/*
 * @Description: 消息提示
 * @Author: ZhangHan
 * @Date: 2025-07-25 18:10:28
 * @LastEditTime: 2025-07-25 18:10:33
 * @LastEditors: ZhangHan
 */
import { isString } from "@/utils/is";

export function useMessage() {
  // 成功提示
  function success(opt:any) {
    show(opt, "success");
  }

  // 失败提示
  function error(opt:any) {
    show(opt, "error");
  }

  // 信息提示
  function show(opt:any, icon: "success" | "error" | "loading" | "none" = "none") {
    if (!opt) {
      return;
    }

    if (isString(opt)) {
      uni.showToast({ title: opt, icon, duration: 2000 });
    } else {
      uni.showToast({ icon, ...opt });
    }
  }

  return {
    success,
    error,
    show,
  };
}
